<?php if (!defined('BASEPATH')) exit('No direct access allowed.');

class User
{
	/**
     * user domain
     *
     * @access private
     * @var array
     */
    private $_user = array();

	/**
     * 用户ID
     *
     * @access public
     * @var integer
     */
	public $uid = 0;

	/**
     * Email
     *
     * @access public
     * @var string
     */
	public $mail = '';

	/**
     * 所属用户组
     *
     * @access public
     * @var string
     * (visitor, user, admin)
     */
	public $group = 'visitor';

	/**
	 * 所属城市Id
	 */
	public $cid = 0;

	/**
	 * 所属城市Id
	 */
	public $city = '';

	/**
    * CI句柄
    *
    * @access private
    * @var object
    */
	private $_CI;

	 /**
     * 构造函数
     *
     * @access public
     * @return void
     */
    public function __construct()
    {
        /** 获取CI句柄 */
		$this->_CI = & get_instance();

		$this->_user = unserialize($this->_CI->session->userdata('user'));

		/** 初始化工作 */
		if(!empty($this->_user))
		{
			$this->uid = $this->_user['uid'];
			$this->mail = $this->_user['mail'];
			$this->group = $this->_user['group'];
			$this->cid = $this->_user['cid'];
			$this->city = $this->_user['city'];
		}
    }

    public function is_visitor(){
    	return 'visitor' == $this->group;
    }

    public function is_user(){
    	return 'user' == $this->group;
    }

    public function is_admin(){
    	return 'admin' == $this->group;
    }
}

/* End of file User.php */
/* Location: ./application/libraries/User.php */